public class Solution {
    public List<List<String>> groupAnagrams(String[] strs) {
        HashMap<String, List<String>> res = new HashMap<>();
        for (String s : strs) {
            char[] cs = s.toCharArray();
            Arrays.sort(cs);
            String sortedStr = new String(cs);
            if (!res.containsKey(sortedStr)) {
                res.put(sortedStr, new LinkedList<>());
            }
            res.get(sortedStr).add(s);
        }
        return res.values().stream().toList();
    }
}
